﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:ViewModelLocator xmlns:vm="clr-namespace:TeacherLeftHand.ViewModel"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
  
  OR (WPF only):
  
  xmlns:vm="clr-namespace:TeacherLeftHand.ViewModel"
  DataContext="{Binding Source={x:Static vm:ViewModelLocator.ViewModelNameStatic}}"
*/

using TeacherLeftHand.Util;

namespace TeacherLeftHand.ViewModel
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// Use the <strong>mvvmlocatorproperty</strong> snippet to add ViewModels
    /// to this locator.
    /// </para>
    /// <para>
    /// In Silverlight and WPF, place the ViewModelLocator in the App.xaml resources:
    /// </para>
    /// <code>
    /// &lt;Application.Resources&gt;
    ///     &lt;vm:ViewModelLocator xmlns:vm="clr-namespace:TeacherLeftHand.ViewModel"
    ///                                  x:Key="Locator" /&gt;
    /// &lt;/Application.Resources&gt;
    /// </code>
    /// <para>
    /// Then use:
    /// </para>
    /// <code>
    /// DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
    /// </code>
    /// <para>
    /// You can also use Blend to do all this with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// <para>
    /// In <strong>*WPF only*</strong> (and if databinding in Blend is not relevant), you can delete
    /// the ViewModelName property and bind to the ViewModelNameStatic property instead:
    /// </para>
    /// <code>
    /// xmlns:vm="clr-namespace:TeacherLeftHand.ViewModel"
    /// DataContext="{Binding Source={x:Static vm:ViewModelLocator.ViewModelNameStatic}}"
    /// </code>
    /// </summary>
    public class ViewModelLocator
    {
        #region Translation
        private static TranslationContext _translationViewModel;

        /// <summary>
        /// Gets the Translation property.
        /// </summary>
        public static TranslationContext TranslationStatic
        {
            get
            {
                if (_translationViewModel == null)
                {
                    CreateTranslation();
                }

                return _translationViewModel;
            }
        }

        /// <summary>
        /// Gets the Translation property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public TranslationContext Translation
        {
            get
            {
                return TranslationStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the Translation property.
        /// </summary>
        public static void ClearTranslation()
        {
            if (_translationViewModel != null)
            {
                _translationViewModel.Cleanup();
                _translationViewModel = null;
            }

        }

        /// <summary>
        /// Provides a deterministic way to create the Translation property.
        /// </summary>
        public static void CreateTranslation()
        {
            if (_translationViewModel == null)
            {
                _translationViewModel = new TranslationContext();
            }
        }
        #endregion

        #region KI Management
        #region KnowledgeItem _ KI Management
        private static KnowledgeItemViewModel _knowledgeItemViewModel;

        /// <summary>
        /// Gets the KnowledgeItem property.
        /// </summary>
        public static KnowledgeItemViewModel KnowledgeItemStatic
        {
            get
            {
                if (_knowledgeItemViewModel == null)
                {
                    CreateKnowledgeItem();
                }

                return _knowledgeItemViewModel;
            }
        }

        /// <summary>
        /// Gets the KnowledgeItem property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public KnowledgeItemViewModel KnowledgeItem
        {
            get
            {
                return KnowledgeItemStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the KnowledgeItem property.
        /// </summary>
        public static void ClearKnowledgeItem()
        {
            if (_knowledgeItemViewModel != null)
            {
                _knowledgeItemViewModel.Cleanup();
                _knowledgeItemViewModel = null;
            }

        }

        /// <summary>
        /// Provides a deterministic way to create the KnowledgeItem property.
        /// </summary>
        public static void CreateKnowledgeItem()
        {
            if (_knowledgeItemViewModel == null)
            {
                _knowledgeItemViewModel = new KnowledgeItemViewModel();
            }
        }
        #endregion

        #region AddNewKI
        private static CreateNewKIViewModel _createNewKiViewModel;

        /// <summary>
        /// Gets the CreateNewKI property.
        /// </summary>
        public static CreateNewKIViewModel CreateNewKIStatic
        {
            get
            {
                if (_createNewKiViewModel == null)
                {
                    CreateCreateNewKI();
                }

                return _createNewKiViewModel;
            }
        }

        /// <summary>
        /// Gets the CreateNewKI property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public CreateNewKIViewModel CreateNewKI
        {
            get
            {
                return CreateNewKIStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the CreateNewKI property.
        /// </summary>
        public static void ClearCreateNewKI()
        {
            if (_createNewKiViewModel != null)
            {
                _createNewKiViewModel.Cleanup();
                _createNewKiViewModel = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the CreateNewKI property.
        /// </summary>
        public static void CreateCreateNewKI()
        {
            if (_createNewKiViewModel == null)
            {
                _createNewKiViewModel = new CreateNewKIViewModel();
            }
        }


        #endregion

        #region KIManagementView
        private static KnowledgeItemManageViewModel _knowledgeItemManageViewModel;

        /// <summary>
        /// Gets the KnowledgeItemManage property.
        /// </summary>
        public static KnowledgeItemManageViewModel KnowledgeItemManageStatic
        {
            get
            {
                if (_knowledgeItemManageViewModel == null)
                {
                    CreateKnowledgeItemManage();
                }

                return _knowledgeItemManageViewModel;
            }
        }

        /// <summary>
        /// Gets the KnowledgeItemManage property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public KnowledgeItemManageViewModel KnowledgeItemManage
        {
            get
            {
                return KnowledgeItemManageStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the KnowledgeItemManage property.
        /// </summary>
        public static void ClearKnowledgeItemManage()
        {
            if (_knowledgeItemManageViewModel != null)
            {
                _knowledgeItemManageViewModel.Cleanup();
                _knowledgeItemManageViewModel = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the KnowledgeItemManage property.
        /// </summary>
        public static void CreateKnowledgeItemManage()
        {
            if (_knowledgeItemManageViewModel == null)
            {
                _knowledgeItemManageViewModel = new KnowledgeItemManageViewModel();
            }
        }

        #endregion

        #endregion

        #region TeachingPlan
        #region Activity
        private static ActivityViewModel _activityViewModel;

        /// <summary>
        /// Gets the Activity property.
        /// </summary>
        public static ActivityViewModel ActivityStatic
        {
            get
            {
                if (_activityViewModel == null)
                {
                    CreateActivity();
                }

                return _activityViewModel;
            }
        }

        /// <summary>
        /// Gets the Activity property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public ActivityViewModel Activity
        {
            get
            {
                return ActivityStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the Activity property.
        /// </summary>
        public static void ClearActivity()
        {
            if (_activityViewModel != null)
            {
                _activityViewModel.Cleanup();
                _activityViewModel = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the Activity property.
        /// </summary>
        public static void CreateActivity()
        {
            if (_activityViewModel == null)
            {
                _activityViewModel = new ActivityViewModel();
            }
        }
        #endregion

        #region KnowledgeItemList _ Compose Teaching Plan
        private static KnowledgeItemListViewModel _knowledgeItemListViewModel;

        /// <summary>
        /// Gets the KnowledgeItemList property.
        /// </summary>
        public static KnowledgeItemListViewModel KnowledgeItemListStatic
        {
            get
            {
                if (_knowledgeItemListViewModel == null)
                {
                    CreateKnowledgeItemList();
                }

                return _knowledgeItemListViewModel;
            }
        }

        /// <summary>
        /// Gets the KnowledgeItemList property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public KnowledgeItemListViewModel KnowledgeItemList
        {
            get
            {
                return KnowledgeItemListStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the KnowledgeItemList property.
        /// </summary>
        public static void ClearKnowledgeItemList()
        {
            if (_knowledgeItemListViewModel != null)
            {
                _knowledgeItemListViewModel.Cleanup();
                _knowledgeItemListViewModel = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the KnowledgeItemList property.
        /// </summary>
        public static void CreateKnowledgeItemList()
        {
            if (_knowledgeItemListViewModel == null)
            {
                _knowledgeItemListViewModel = new KnowledgeItemListViewModel();
            }
        }

        #endregion



        #region TeachingMethodListViewModel _ Compose Teaching Plan
        private static TeachingMethodListViewModel _teachingMethodListViewModel;

        /// <summary>
        /// Gets the TeachingMethodList property.
        /// </summary>
        public static TeachingMethodListViewModel TeachingMethodListStatic
        {
            get
            {
                if (_teachingMethodListViewModel == null)
                {
                    CreateTeachingMethodList();
                }

                return _teachingMethodListViewModel;
            }
        }

        /// <summary>
        /// Gets the TeachingMethodList property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public TeachingMethodListViewModel TeachingMethodList
        {
            get
            {
                return TeachingMethodListStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the TeachingMethodList property.
        /// </summary>
        public static void ClearTeachingMethodList()
        {
            if (_teachingMethodListViewModel != null)
            {
                _teachingMethodListViewModel.Cleanup();
                _teachingMethodListViewModel = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the TeachingMethodList property.
        /// </summary>
        public static void CreateTeachingMethodList()
        {
            if (_teachingMethodListViewModel == null)
            {
                _teachingMethodListViewModel = new TeachingMethodListViewModel();
            }
        }
        #endregion

        #region TeachingPlanViewModel
        private static TeachingPlanViewModel _teachingPlanViewModel;

        /// <summary>
        /// Gets the TeachingPlan property.
        /// </summary>
        public static TeachingPlanViewModel TeachingPlanStatic
        {
            get
            {
                if (_teachingPlanViewModel == null)
                {
                    CreateTeachingPlan();
                }

                return _teachingPlanViewModel;
            }
        }

        /// <summary>
        /// Gets the TeachingPlan property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public TeachingPlanViewModel TeachingPlan
        {
            get
            {
                return TeachingPlanStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the TeachingPlan property.
        /// </summary>
        public static void ClearTeachingPlan()
        {
            if (_teachingPlanViewModel != null)
            {
                _teachingPlanViewModel.Cleanup();
                _teachingPlanViewModel = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the TeachingPlan property.
        /// </summary>
        public static void CreateTeachingPlan()
        {
            if (_teachingPlanViewModel == null)
            {
                _teachingPlanViewModel = new TeachingPlanViewModel();
            }
        }
        #endregion
        #endregion

        #region TM Management
        #region TeachingMethodViewModel _ TM Management
        private static TeachingMethodViewModel _teachingMethodViewModel;

        /// <summary>
        /// Gets the TeachingMethod property.
        /// </summary>
        public static TeachingMethodViewModel TeachingMethodStatic
        {
            get
            {
                if (_teachingMethodViewModel == null)
                {
                    CreateTeachingMethod();
                }

                return _teachingMethodViewModel;
            }
        }

        /// <summary>
        /// Gets the TeachingMethod property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public TeachingMethodViewModel TeachingMethod
        {
            get
            {
                return TeachingMethodStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the TeachingMethod property.
        /// </summary>
        public static void ClearTeachingMethod()
        {
            if (_teachingMethodViewModel != null)
            {
                _teachingMethodViewModel.Cleanup();
                _teachingMethodViewModel = null;
            }

        }

        /// <summary>
        /// Provides a deterministic way to create the TeachingMethod property.
        /// </summary>
        public static void CreateTeachingMethod()
        {
            if (_teachingMethodViewModel == null)
            {
                _teachingMethodViewModel = new TeachingMethodViewModel();
            }
        }
        #endregion

        #region CreateNewTM
        private static CreateNewTMViewModel _createNewTmViewModel;

        /// <summary>
        /// Gets the CreateNewTM property.
        /// </summary>
        public static CreateNewTMViewModel CreateNewTMStatic
        {
            get
            {
                if (_createNewTmViewModel == null)
                {
                    CreateCreateNewTM();
                }

                return _createNewTmViewModel;
            }
        }

        /// <summary>
        /// Gets the CreateNewTM property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public CreateNewTMViewModel CreateNewTM
        {
            get
            {
                return CreateNewTMStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the CreateNewTM property.
        /// </summary>
        public static void ClearCreateNewTM()
        {
            if (_createNewTmViewModel != null)
            {
                _createNewTmViewModel.Cleanup();
                _createNewTmViewModel = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the CreateNewTM property.
        /// </summary>
        public static void CreateCreateNewTM()
        {
            if (_createNewTmViewModel == null)
            {
                _createNewTmViewModel = new CreateNewTMViewModel();
            }
        }


        #endregion

        #region TeachingMethodManagementView
        private static TeachingMethodManageViewModel _teachingMethodManageViewModel;

        /// <summary>
        /// Gets the TeachingMethodManage property.
        /// </summary>
        public static TeachingMethodManageViewModel TeachingMethodManageStatic
        {
            get
            {
                if (_teachingMethodManageViewModel == null)
                {
                    CreateTeachingMethodManage();
                }

                return _teachingMethodManageViewModel;
            }
        }

        /// <summary>
        /// Gets the TeachingMethodManage property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public TeachingMethodManageViewModel TeachingMethodManage
        {
            get
            {
                return TeachingMethodManageStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the TeachingMethodManage property.
        /// </summary>
        public static void ClearTeachingMethodManage()
        {
            if (_teachingMethodManageViewModel != null)
            {
                _teachingMethodManageViewModel.Cleanup();
                _teachingMethodManageViewModel = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the TeachingMethodManage property.
        /// </summary>
        public static void CreateTeachingMethodManage()
        {
            if (_teachingMethodManageViewModel == null)
            {
                _teachingMethodManageViewModel = new TeachingMethodManageViewModel();
            }
        }
        #endregion

        #endregion

        #region MainWindow
        private static MainWindowViewModel _mainWindowViewModel;

        /// <summary>
        /// Gets the MainWindow property.
        /// </summary>
        public static MainWindowViewModel MainWindowStatic
        {
            get
            {
                if (_mainWindowViewModel == null)
                {
                    CreateMainWindow();
                }

                return _mainWindowViewModel;
            }
        }

        /// <summary>
        /// Gets the MainWindow property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainWindowViewModel MainWindow
        {
            get
            {
                return MainWindowStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the MainWindow property.
        /// </summary>
        public static void ClearMainWindow()
        {
            if (_mainWindowViewModel != null)
            {
                _mainWindowViewModel.Cleanup();
                _mainWindowViewModel = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the MainWindow property.
        /// </summary>
        public static void CreateMainWindow()
        {
            if (_mainWindowViewModel == null)
            {
                _mainWindowViewModel = new MainWindowViewModel();
            }
        }
        #endregion

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            ClearTranslation();

            ClearKnowledgeItem();
            ClearKnowledgeItemManage();

            ClearTeachingMethod();
            ClearTeachingMethodManage();

            ClearKnowledgeItemList();
            ClearTeachingMethodList();
            ClearTeachingPlan();

            ClearMainWindow();
        }
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            CreateMainWindow();

            // compose teaching plan view model
            CreateTeachingPlan();
            CreateTeachingMethodList();
            CreateKnowledgeItemList();

            CreateTranslation();
        }

    }
}